-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(tanstackstart-react): Auto-instrument global middleware #18844
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
This reverts commit 286f624.
50e7961 to
2706bc0
Compare
node-overhead report 🧳Note: This is a synthetic benchmark with a minimal express app and does not necessarily reflect the real-world performance impact in an application.
|
size-limit report 📦
|
| return `${key}: wrapMiddlewaresWithSentry(${objContents})`; | ||
| } | ||
| // Track middlewares that couldn't be auto-wrapped | ||
| if (contents.trim()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Q: why do we trim the contents here? To make sure it's not an empty file? Just curious
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just in case people have weird formatting and we match whitespace only when trying to match the middlewares, unlikely case but shouldn't hurt to have it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.
| const skippedMiddlewares: string[] = []; | ||
|
|
||
| transformed = transformed.replace( | ||
| /(requestMiddleware|functionMiddleware)\s*:\s*\[([^\]]*)\]/g, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Middleware regex matches arrays outside createStart scope
Low Severity
The comment on line 29 states the plugin will "Only wrap requestMiddleware and functionMiddleware in createStart()" but the implementation wraps these patterns anywhere in files that merely contain createStart(. The regex at line 44 matches all occurrences file-wide. If a file defines middleware arrays in separate config objects outside the createStart() call, they would also be transformed unexpectedly, potentially wrapping unrelated middleware.
This PR adds automatic instrumentation for global request and function middleware in TanStack Start applications.
Overview
The sentryTanstackStart Vite plugin now automatically wraps requestMiddleware and functionMiddleware arrays in
createStart()with Sentry instrumentation. This is done via a source code transformation during the build that converts:into:
Usage
Auto-instrumentation is enabled by default. To explicitly disable it:
This should give users flexibility in case things go wrong.
Implementation Details
createStart()wrapMiddlewaresWithSentryTesting
sentryTanstackStartpluginautoInstrumentMiddlewareFollow-ups
Future PRs will add support for non-global request/function middleware. This PR focuses on global middleware to make it a bit easier to review. I also want to give users a bit more control by allowing them to disable auto-instrumentation on a file-level, but this doesn't make sense yet since the current implementation only patches a single file anyways.
Closes #18845